<?php

namespace app\admin\model;

use think\Model;

class TravelMember extends Model
{
    // 表名
    protected $name = 'travel_member';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    
    // 追加属性
    protected $append = [
        'paid_text',
        'check_time_text'
    ];
    

    
    public function getPaidList()
    {
        return ['0' => __('Paid 0'),'1' => __('Paid 1'),'2' => __('Paid 2')];
    } 
        //is_checkin
    public function getIsCheckinList()
    {
        return ['0' => '未签到','1' => '已签到'];
    }     
    
    public function getIsCheckinAttr($value, $data)
    {        
        $value = $value ? $value : $data['is_checkin'];
        $list = $this->getIsCheckinList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getPaidTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['paid'];
        $list = $this->getPaidList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getCheckTimeTextAttr($value, $data)
    {
        $value = $value ? $value : $data['check_time'];
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setCheckTimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }

    public function travel()
    {
        return $this->belongsTo('Travel', 'travel_id')->setEagerlyType(0);
    }



}
